/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */

package cn.edu.thu.log.clean;

import java.util.ArrayList;
import java.util.HashMap;

import cn.edu.thu.log.read.LogBufferModified;
import cn.edu.thu.log.web.service.WebConfigReadService;
import cn.edu.thu.log.web.service.impl.WebConfigReadServiceImpl;



/**
 * use the productlist to filter the loading log
 * 
 * @author wan
 * 
 */
public class ProductFilter {
	private ArrayList<String> allproducts;
	private WebConfigReadService webconfigreadservice;
	public   HashMap<String,String> productlist = new HashMap<String ,String>(); 
/**
 * 
 */
	public ProductFilter() {
		webconfigreadservice = WebConfigReadServiceImpl.instance();
		allproducts = new ArrayList<String>();	
		productlist.put("81cbccdb855f23fdfe97f669a9818b50", "generalclick2");
		productlist.put("289b4b9695c7885a32eb98c76d0ae3e5", "otherpage2");
		productlist.put("7ce008e9403e98bb292e00bac594fb71", "imagesearch2");
		productlist.put("5f21ef5709825ff493d99a2a2d50d8bc", "pagesearch2");
		productlist.put("bdcda250ca7e4c0b8ff1826fa597c998", "newssearch2");
		
	}
	/**
	 * 
	 * @param productslist
	 */
	public ProductFilter(String productslist) {
		webconfigreadservice = WebConfigReadServiceImpl.instance();
		String [] tempstrs = productslist.split("/");
		allproducts = new ArrayList<String>();	
		for( int i = 0 ; i < tempstrs.length ; i ++) {
			allproducts.add(tempstrs[i]);
		}
		productlist.put("81cbccdb855f23fdfe97f669a9818b50", "generalclick2");
		productlist.put("289b4b9695c7885a32eb98c76d0ae3e5", "otherpage2");
		productlist.put("7ce008e9403e98bb292e00bac594fb71", "imagesearch2");
		productlist.put("5f21ef5709825ff493d99a2a2d50d8bc", "pagesearch2");
		productlist.put("bdcda250ca7e4c0b8ff1826fa597c998", "newssearch2");
		
	}
/**
 * 
 * @param record parameter
 * @return
 */
	public boolean profilter(LogBufferModified record) {
		allproducts.addAll(webconfigreadservice.getProductsList());		

		// 第8个tag记录的就是产品名称
		if(record.getContent("lid")== null || record.getContent("lid").equalsIgnoreCase("")){
			return false;			
		}
		String productname = productlist.get(record.getContent("lid"));
		// 如果分析产品列表中不包含本记录所代表的产品，则返回false，删除本条记录
		if (!allproducts.contains(productname)) {
			return false;
		}

		return true;

	}
	
}
